package com.innovation.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 时间相关的工具类
 * @author Administrator
 *
 */
public class TimeUtil {
	/**秒*/
	public static int SECOND = 1;
	/**分钟*/
	public static int MINUTE = SECOND * 60;
	/**小时*/
	public static int HOUR = MINUTE * 60;
	/**天*/
	public static int DAY = HOUR * 24;
	
	/**
	 * 当前时间(单位:秒)
	 * @return
	 */
	public static int now(){
		return (int)(System.currentTimeMillis() / 1000);
	}
	
	/**
	 * 判断时间是否为今天
	 * @param time 时间:单位s
	 * @return
	 */
	public static boolean isToday(int time){
		if(time == 0){
			return false;
		}
		Calendar cal = Calendar.getInstance();
		int year = cal.get(Calendar.YEAR);
		int day = cal.get(Calendar.DAY_OF_YEAR);
		
		cal.setTimeInMillis(time * 1000L);
		if(year == cal.get(Calendar.YEAR) && day == cal.get(Calendar.DAY_OF_YEAR)){
			return true;
		}
		return false;
	}
	
	
	public static void main(String[] args) {
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(1381226929000L);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		System.out.println(sdf.format(cal.getTime()));
		
		
		
		try {
			Date date = sdf.parse("2013-11-21 14:19:56");
			System.out.println(date.getTime());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
	}
}
